#include <stdio.h>

int main()
{
    int n = 0;
    int m = 0;
    scanf("%d %d",&n,&m);
    int i = 0;
    int j = 0;
    int arr1[n][m];
    int arr2[n][m];
    for(i=0;i<n;i++)
    {
        for (j=0;j<m;j++)
        {
            scanf("%d ",&arr1[i][j]);
        }
    }
    int count = 0;
    int sum = n*m;
    for(i=0;i<n;i++)
    {
        for (j=0;j<m;j++)
        {
            scanf("%d ",&arr2[i][j]);
            if(arr2[i][j]==arr1[i][j])
                count++;
        }
    }
    if(count==sum)
        printf("Yes\n");
    else
        printf("No\n");
    return 0;
}
